import sbtcrossproject.CrossPlugin.autoImport.{crossProject, CrossType}

val nameStr="live_fat_h2"
val scalaVersionStr="2.13.5"

name := nameStr

version := "0.1"

scalaVersion := scalaVersionStr

lazy val server = (project in file("server")).settings(commonSettings).settings(
  scalaJSProjects := Seq(client),
  name := nameStr,
  version := "1.0",
  Assets / pipelineStages := Seq(scalaJSPipeline),
  pipelineStages := Seq(digest, gzip),
  Compile / compile := ((Compile / compile) dependsOn scalaJSPipeline).value,
  libraryDependencies ++= Seq(
    "com.vmunier" %% "scalajs-scripts" % "1.2.0",
    guice,
    specs2 % Test,
    ehcache,
    "com.typesafe.play" %% "play-slick" % "4.0.2",
    "com.typesafe.slick" %% "slick-codegen" % "3.3.2",
    "com.github.tototoshi" %% "slick-joda-mapper" % "2.4.1",
    "commons-io" % "commons-io" % "2.5",
    "org.apache.poi" % "poi-ooxml" % "3.15",
    "com.github.jurajburian" %% "mailer" % "1.2.4",
    "org.apache.commons" % "commons-math3" % "3.6.1",
    "com.typesafe.play" %% "play-joda-forms" % "2.7.3",
    "com.h2database" % "h2" % "1.4.199",
    "org.apache.xmlgraphics" % "batik-codec" % "1.10",
    "org.typelevel" %% "cats-core" % "2.0.0",
    "org.scala-lang.modules" %% "scala-parallel-collections" % "0.2.0",
    "org.apache.commons" % "commons-lang3" % "3.6",
    "io.github.alexarchambault" %% "data-class" % "0.2.5",
    "com.lihaoyi" %% "os-lib" % "0.7.8",
    "com.lihaoyi" %% "requests" % "0.6.9"
  ),
  scalacOptions ++= {
    Seq("-deprecation", "-feature","-Ymacro-annotations")
  }
).enablePlugins(PlayScala,LauncherJarPlugin,WebScalaJSBundlerPlugin).dependsOn(sharedJvm)

val reactVersion = "17.0.2"

lazy val client = (project in file("client")).settings(commonSettings).settings(
  scalaJSUseMainModuleInitializer := false,
  resolvers += "jitpack" at "https://jitpack.io",
  libraryDependencies ++= Seq(
    "com.lihaoyi" %%% "scalatags" % "0.11.1",
    "me.shadaj" %%% "slinky-web" % "0.7.2",
    "me.shadaj" %%% "slinky-hot" % "0.7.2",
    "com.softwaremill.quicklens" %%% "quicklens" % "1.6.1"
  ),
  scalacOptions ++= {
    Seq("-deprecation", "-feature","-Ymacro-annotations")
  },
  Compile / npmDependencies ++= Seq(
    "jquery" -> "3.5.0",
    "react-dom" -> reactVersion,
    "react" -> reactVersion,
    "css-loader" -> "3.4.2",
    "webpack-merge" -> "4.2.2",
    "style-loader" -> "1.1.3",
    "file-loader" -> "5.1.0",
    "html-webpack-plugin" -> "5.2.0",
    "plotly.js-dist-min" -> "2.11.1"
  ),
  webpackBundlingMode := BundlingMode.LibraryAndApplication(),
  webpackConfigFile := Some(baseDirectory.value / "my.custom.webpack.config.js")
).enablePlugins(ScalaJSBundlerPlugin).dependsOn(sharedJs)

lazy val shared = crossProject(JSPlatform, JVMPlatform)
  .crossType(CrossType.Pure)
  .in(file("shared"))
  .settings(commonSettings).settings(
  scalacOptions ++= {
    Seq("-deprecation", "-feature","-Ymacro-annotations")
  },
  libraryDependencies ++= Seq(
    "com.chuusai" %% "shapeless" % "2.3.3",
    "io.github.alexarchambault" %% "data-class" % "0.2.5",
    "com.github.alexarchambault" %%% "argonaut-shapeless_6.3" % "1.3.0"
  )
).jsConfigure(_.enablePlugins(ScalaJSWeb))

lazy val sharedJvm = shared.jvm
lazy val sharedJs = shared.js

lazy val commonSettings = Seq(
  scalaVersion := scalaVersionStr
)

onLoad in Global := (onLoad in Global).value andThen { s: State => "project server" :: s }
